using System;
using CGF;
using UnityEngine;
using UnityEngine.UI;

public class PersonalInfo : MonoBehaviour
{
    public Text Nickname, ID, Vip;
    public CButton btnCopyID, vipIcon;

    void Start()
    {
        btnCopyID.SetClick(() =>
        {
            CopyAndPaste.Copy(UserInfo.UserId);
            Tip.Open(CommAssets.instance.I18N_copy_success);
        });
        
        vipIcon.SetClick(() =>
        {
            PanelVIPRule.Open();
        });

        OnUserInfoUpdate(new Event_UserInfoUpdate());
        EventManager.Add<Event_UserInfoUpdate>(OnUserInfoUpdate);
    }

    private void OnEnable()
    {
        OnUserInfoUpdate(new Event_UserInfoUpdate());
    }

    private void OnUserInfoUpdate(Event_UserInfoUpdate e)
    {
        //TODO
        /*if (UserInfo.IsUsernameLogin)
        {
            TabMe.Nickname.text = $"{UserInfo.Info["user_name"]}\n<size=30><color=#bbbbbb>{CommAssets.instance.I18N_nickname}: {UserInfo.Info["name"]}</color></size>";
        }
        else*/
        {
            Nickname.text = UserInfo.Info["name"].ToString();
        }
        ID.text = $"ID: {UserInfo.Info["id"]}";
        btnCopyID.gameObject.SetActive(!UserInfo.IsUsernameLogin);
        int level = (int)UserInfo.Info["level"];
        Vip.text = CommAssets.instance.vipNames[level];
    }

    private void OnDestroy()
    {
        EventManager.Remove<Event_UserInfoUpdate>(OnUserInfoUpdate);
    }
}
